package com.woniuxy.reader.mapper;

import com.woniuxy.reader.entity.Book;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.reader.vo.BookVO;
import com.woniuxy.reader.vo.BookVOOO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author zh_o
 * @since 2020-10-12
 */
public interface BookMapper extends BaseMapper<Book> {
    @Select("select b.* from book b LEFT JOIN author a on b.author_id=a.author_id  LEFT JOIN editor e on e.editor_id=a.editor_id where e.editor_id=#{id} and a.`level`='签约写手'")
    List<Book> selectData(int id);

    @Select("select b.* from book b LEFT JOIN author a on a.author_id=b.author_id where a.`level`='未签约'")
    List<Book> selectNoSign();

    @Update("update book set flag=0 where book_id=#{bookid}")
    void updateBook(int bookid);

    @Update("update book set flag=2 where book_id=#{bookid}")
    void updateBookFlag(int bookid);

    @Select("select book_id,book_name,status,count_day,count from book")
    List<Book> selectAllBook();

    @Update("update book set flag=3 where book_id=#{bookid}")
    void setBoutique(int bookid);

    @Update("update book set flag=1 where book_id=#{bookid}")
    void setnormal(int bookid);

    @Select("select b.*  from book  b join book_data bd on b.book_id = bd.book_id  where category_id = #{id} group by bd.click_number DESC ")
    List<Book> selectBooksByCategoryIdAndClickNum(int id);


    @Select("select b.*  from book  b join book_data bd on b.book_id = bd.book_id  where category_id = #{id} group by bd.collection DESC ")
    List<Book> selectBooksByCategoryIdAndCollection(int id);

    @Select("select b.book_id,c.category_name,b.book_name,b.count,b.create_time,b.update_time,b.description from book b left JOIN category c on b.category_id=c.category_id where b.author_id=#{authorid}")
    List<BookVO> managerselect(String authorid);

    @Select("select b.book_id,b.image,b.book_name,b.description,a.pen_name,c.category_name,b.status,b.count,b.count_day,b.create_time,b.update_time,b.flag from book b left JOIN author a on b.author_id=a.author_id LEFT JOIN category c on b.category_id=c.category_id")
    List<BookVOOO> selectAllBookDetail();

}
